import pygame
from pygame.sprite import Sprite
class Alien(Sprite):
	def __init__(self,my_settings,screen):
		#初始化外星人并设置其起始位置
		super().__init__()
		self.screen = screen
		self.my_settings = my_settings
		#加载外星人图像
		self.image = pygame.image.load('alien.bmp')
		self.rect = self.image.get_rect()
		#每个外星人最初都在屏幕左上角
		self.rect.x = self.rect.width
		self.rect.y = self.rect.height
		#存储外星人的准确位置
		self.x = float(self.rect.x)
	
	def blitme(self):
		#在指定位置绘制外星人
		self.screen.blit(self.image,self.rect)
	def update(self):
		self.x += (self.my_settings.alien_speed_factor * self.my_settings.fleet_direction)
		self.rect.x = self.x
	#检查外星人是否碰到了屏幕边缘
	def check_edges(self):
		screen_rect = self.screen.get_rect()
		if self.rect.right >= screen_rect.right:
			return True
		elif self.rect.left <= 0:
			return True
